﻿using System;
using System.Management;
using System.Management.Automation;
using Microsoft.SharePoint;

namespace SPPoSh.Cmdlets.Artefacts.Views
{
    [Cmdlet(VerbsCommon.Get, "SPView")]
    public class GetSPViewCmdlet : Cmdlet
    {
        [Parameter(Position = 0, Mandatory = true, HelpMessage = "View's name")]
        public string Name;

        [Parameter(Position = 1, Mandatory = true, HelpMessage = "List Object")]
        public SPList List;

        protected override void ProcessRecord()
        {
            SPViewCollection viewCollection = List.Views;
            SPView view = null;
            try
            {
                view = viewCollection[Name];
            }
            catch { }
            this.WriteObject(view);
        }
    }
}
